package com.asset.dispoal.abolishPool.service.common;

import com.asset.dispoal.abolishPool.domain.db.entity.GbAbolishCaseContent;
import com.asset.dispoal.abolishPool.domain.db.mapper.AbolishCaseContentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @description:
 * @author: yf
 * @date: 2022-09-22 15:53:59
 */
@Repository
public class DeletebolishPoolCommand implements BaseCommand<String, Result> {
    @Autowired
    private AbolishCaseContentMapper abolishCaseContentMapper;

    @Override
    public Result execute(String configId) {
        GbAbolishCaseContent caseContent = abolishCaseContentMapper.queryById(configId);
        if (caseContent.getUseDefault().equals("1")) {
            return Result.faild("当前为默认配置不能删除！！");
        }

        int update = abolishCaseContentMapper.update(GbAbolishCaseContent.builder()
                .id(caseContent.getId())
                .state("2")
                .build());
        return update <= 0 ? Result.faild("数据删除失败！") : Result.ok();
    }
}
